#函数装饰器
# def kuozhan(cls):
#     def func2():
#         print('在装饰器中追加的类方法')
#     cls.name='在装饰器中追加的类属性'
#     cls.func2=func2
#     return cls
#
# @kuozhan
# class Demo():
#     def func():
#         print('Demo类中定义的func方法')
# # Demo()
# # Demo.func()
# Demo.func2()

#类装饰器
class Kuozhan():
    def __call__(self,cls):
        self.cls=cls
        return self.newfunc
    def newfunc(self):
        self.cls.name='类装饰器追加的属性'
        self.cls.func2=self.func2
        return self.cls()
    def func2(self):
        print('在类装饰器中追加的方法')

@Kuozhan()
class Demo():
    def func(self):
        print('在Demo类中定义的func方法')
zs=Demo()
zs.func()
print(zs.name)
zs.func2()